import {
  getSwiperApi,
  getHotCateApi,
  getGoodfoodApi
} from '@/api/cookbookApi'

import {
  COOKBOOKTYPE_ADD_SWIPER,
  COOKBOOKTYPE_ADD_HOTCATE,
  COOKBOOKTYPE_ADD_GOODFOOD
} from '../types/cookbookType'

// ----------------- 添加幻灯片
const addSwiperActionCreator = data => ({
  type: COOKBOOKTYPE_ADD_SWIPER,
  data
})
export const addSwiperAction = () => async disptch => {
  let ret = await getSwiperApi()
  disptch(addSwiperActionCreator(ret.data))
  return true
}

// ----------------- 添加热门分类
const addHotCateActionCreator = data => ({
  type: COOKBOOKTYPE_ADD_HOTCATE,
  data
})
export const addHotCateAction = () => async disptch => {
  let ret = await getHotCateApi()
  disptch(addHotCateActionCreator(ret.data))
  return true
}

// ----------------- 添加好菜
const addGoodfoodActionCreator = data => ({
  type: COOKBOOKTYPE_ADD_GOODFOOD,
  data
})
export const addGoodfoodAction = () => async disptch => {
  let ret = await getGoodfoodApi()
  disptch(addGoodfoodActionCreator(ret.data))
  return true
}